package net.hn.hnms.biz.safety.trinity.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import net.hn.hnms.biz.api.feign.model.DataStateVo;
import net.hn.hnms.biz.common.jpa.utils.ResponsePage;
import net.hn.hnms.biz.safety.trinity.entity.HiddenDangerRecordDto;
import net.hn.hnms.biz.safety.trinity.entity.HiddenDangerRecordVo;
import net.hn.hnms.biz.safety.trinity.service.HiddenDangerRecordService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.excel.utils.ExcelUtil;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 智呈物联 pan'sx
 * 2022/7/26 14:56
 * 1.0 version
 */
@RestController
@RequestMapping("manage/hiddenDangerRecord")
@Api(value = "安全隐患台账控制器", tags = {"安全隐患台账"})
public class HiddenDangerRecordController {

    HiddenDangerRecordService hiddenDangerRecordService;

    @Autowired
    public void setHiddenDangerRecordService(HiddenDangerRecordService hiddenDangerRecordService) {
        this.hiddenDangerRecordService = hiddenDangerRecordService;
    }

    @GetMapping("page")
    @ApiOperation("安全隐患台账 分页查询")
    @AutoSetMineCode
    public R<ResponsePage<HiddenDangerRecordVo>> page(PageQuery pageQuery, HiddenDangerRecordDto hiddenDangerRecordDto) {
        return R.ok(hiddenDangerRecordService.page(pageQuery,hiddenDangerRecordDto));
    }

    @GetMapping(value = "export", produces = "application/octet-stream")
    @ApiOperation(value = "导出数据")
    @AutoSetMineCode
    public void export(HttpServletResponse response,PageQuery pageQuery, HiddenDangerRecordDto hiddenDangerRecordDto) throws IOException {
        String fileName = "安全隐患";
        //未转换字典码
        List<HiddenDangerRecordVo> list = hiddenDangerRecordService.page(pageQuery,hiddenDangerRecordDto).getPageData();

//        //字典项赋值
//        DictData dictData = new DictData();
//        Map<String,String> hiddenDangerMajer = dictData.dictToMap("risk_danger_violation_major");
//        Map<String,String> hiddenDangerClass = dictData.dictToMap("risk_danger_class");
//
//        for (HiddenDangerRecordVo hiddenDangerRecordVo:list){
//            String majer = hiddenDangerMajer.get(hiddenDangerRecordVo.getMajor());
//            if (majer!=null){
//                hiddenDangerRecordVo.setMajor(majer);
//            }
//
//            String dangerClass = hiddenDangerClass.get(hiddenDangerRecordVo.getType());
//            if (dangerClass!=null){
//                hiddenDangerRecordVo.setType(dangerClass);
//            }
//        }


        ExcelUtil.exportExcel(list,fileName,HiddenDangerRecordVo.class,response);
    }
    @GetMapping("maxTime")
    @ApiOperation("数据最新时间")
    public R<List<DataStateVo>> getMaxTime(String mineCode, String companyCode){
        return R.ok(hiddenDangerRecordService.getMaxTime( mineCode,companyCode));
    }
}
